package com.aaa.project.controller;


import com.aaa.entity.UCollection;
import com.aaa.project.service.IUCollectionService;
import com.aaa.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangxuhui
 * @since 2023-02-02
 */
@RestController
@RequestMapping("/u-collection")
public class UCollectionController {
    @Resource
    private IUCollectionService iuCollectionService;

    @GetMapping("find")
    public Result find(Principal principal){
        // principL 当前认证成功的用户的信息    解析信息的话靠的是前端传过来的Authorization对应的token值
        // 自动解析   resconfig 里面配置解析的签名
        return new Result(iuCollectionService.getUserSoucang(principal));
    }
    @GetMapping("findDian")
    public Result findDian(Principal principal){
        return new Result<>(iuCollectionService.findDian1(principal));
    }
    @PostMapping("deleted")
    public Result deleted(String id){
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("goodsid",id);
        UCollection uCollection=iuCollectionService.getOne(queryWrapper);
        uCollection.setIsDeleted(1);
        return new Result<>(iuCollectionService.saveOrUpdate(uCollection));
    }
    @PostMapping("deletedPu")
    public Result deletedPu(String id){
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        UCollection uCollection=iuCollectionService.getOne(queryWrapper);
        uCollection.setIsDeleted(1);
        return new Result<>(iuCollectionService.updateById(uCollection));
    }
}

